from django.contrib.auth.models import User
from django.db import models

# Create your models here.

# from DjangoTest import settings

USER_CHOOSE = []

users = User.objects.all().values_list('username')

for i in users:
    USER_CHOOSE.append((i[0], i[0]))

FIND_TYPE_CHOOSE = [
    ('xPath', 'xPath'),
    ('cssSelector', 'cssSelector')
]


class UIPage(models.Model):
    id = models.AutoField(primary_key=True)
    page_name = models.CharField(max_length=200, blank=True, verbose_name="页面名称")
    page_path = models.CharField(max_length=200, blank=True, verbose_name="页面路径")
    system_name = models.CharField(max_length=200, blank=True, verbose_name="系统名称")
    cerater = models.CharField(max_length=200, blank=True, verbose_name="创建者", choices=USER_CHOOSE)
    create_time = models.DateTimeField(u'创建时间', auto_now_add=True, editable=True, null=True)
    update_time = models.DateTimeField(u'更新时间', auto_now=True, null=True)

    class Meta:
        db_table = 'test_ui_pages'
        verbose_name = "页面列表"
        verbose_name_plural = verbose_name

    def __str(self):
        return self.page_name


PAGE_CHOOSE = []
pages = UIPage.objects.all().values_list('page_name')

for i in pages:
    PAGE_CHOOSE.append((i[0], i[0]))


class UIElement(models.Model):
    id = models.AutoField(primary_key=True)
    # upload_to参数是后台admin上传图片的保存位置，我们后续自己写的接口，图片也保存在这个位置
    page = models.ManyToManyField(UIPage)
    element_name = models.CharField(max_length=200, blank=True, verbose_name="元素名称")
    find_type = models.CharField(max_length=200, blank=True, verbose_name="定位方法", choices=FIND_TYPE_CHOOSE,
                                 default=FIND_TYPE_CHOOSE[0][0])
    find_param = models.CharField(max_length=200, blank=True, verbose_name="定位参数")
    another_find_type = models.CharField(max_length=200, blank=True, verbose_name="备用定位方法",
                                         choices=FIND_TYPE_CHOOSE, default=FIND_TYPE_CHOOSE[1][0])
    another_find_param = models.CharField(max_length=200, blank=True, verbose_name="备用定位参数")
    create_time = models.DateTimeField(u'创建时间', auto_now_add=True, editable=True, null=True)
    update_time = models.DateTimeField(u'更新时间', auto_now=True, null=True)

    class Meta:
        db_table = 'test_ui_elements'
        verbose_name = "元素列表"
        verbose_name_plural = verbose_name

    def __str(self):
        return self.element_name


class BusinessProcessTestingTasks(models.Model):
    id = models.AutoField(u'ID', primary_key=True)
    businessProcessName = models.CharField(max_length=200, blank=True, verbose_name="名称")
    # page = models.ForeignKey(UIPage, on_delete=models.CASCADE, default='')
    # element = models.ManyToManyField(UIPage)
    create_time = models.DateTimeField(u'创建时间', auto_now_add=True, editable=True, null=True)
    update_time = models.DateTimeField(u'更新时间', auto_now=True, null=True)

    class Meta:
        db_table = 'Business_Process_Testing_Tasks'
        verbose_name = "业务链列表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.businessProcessName
